﻿using HTB.DevFx.Security;

namespace HTB.DevFx.Mall
{
    class MallResType:IResType
    {
        #region IResType Members

        /// <summary>
        /// 初始化，由<see cref="ResManager"/>调用
        /// </summary>
        /// <param name="setting">配置节</param>
        public void Init(IConfigSetting setting)
        {
        }

        /// <summary>
        /// 资源类型
        /// </summary>
        public string ResType
        {
            get { return "Mall"; }
        }

        /// <summary>
        /// 资源名称
        /// </summary>
        public string Title
        {
            get { return "商场组"; }
        }

        /// <summary>
        /// 判断是否包含指定资源的编码（无权限限制）
        /// </summary>
        /// <param name="resNo">资源的编码（权限范围编号）</param>
        /// <returns>true/false</returns>
        public bool Contains(string resNo)
        {
            return (this as IResType).Contains(resNo, Securitor.Current);
        }

        /// <summary>
        /// 判断是否包含指定资源的编码（有权限限制）
        /// </summary>
        /// <param name="resNo">资源的编码（权限范围编号）</param>
        /// <param name="securityManager">安全管理对象</param>
        /// <returns>true/false</returns>
        public bool Contains(string resNo, ISecurityManager securityManager)
        {
            return securityManager.GroupManager.Contains(resNo);
        }

        /// <summary>
        /// 列出所有的资源（无权限限制）
        /// </summary>
        /// <returns>资源列表</returns>
        public Resource[] ListItem()
        {
            return (this as IResType).ListItem(Securitor.Current);
        }

        /// <summary>
        /// 列出所有的资源（有权限限制）
        /// </summary>
        /// <param name="securityManager">安全管理对象</param>
        /// <returns>资源列表</returns>
        public Resource[] ListItem(ISecurityManager securityManager)
        {
            Mall[] malls = securityManager.GroupManager.ListItem();
            Resource[] resources = new Resource[malls.Length + 1];
            resources[0] = new Resource((this as IResType).ResType, null, "所有组");
            for (int i = 0; i < groups.Length; i++)
            {
                resources[i + 1] = new Resource((this as IResType).ResType, malls[i].GroupNo, malls[i].Title);
            }
            return resources;
        }

        #endregion
    }
}
